home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / Spiro3 / Spiro3View.m < prev   
Text File  |  1993-02-12  |  3KB  |  145 lines

  1. #import <appkit/NXImage.h>
  2. #import <appkit/Window.h>
  3. #import <appkit/Panel.h>                // for NXRunAlertPanel()
  4. #import <dpsclient/wraps.h>
  5. #import <libc.h>
  6. #import <math.h>
  7. #import "Spiro3View.h"
  8.  
  9.  
  10.  
  11. @implementation Spiro3View:View                
  12.  
  13. - oneStep
  14. {
  15.   float mx, my;
  16.   
  17. // Get mouse pos 
  18.   PScurrentmouse(winNum, &mx, &my);
  19.  
  20. //  A rather overwrought way of setting drho and drad, see 'pinc' later
  21. //  xdif=(mx-midx)/bounds.size.width;
  22. //  ydif=(my-midy)/bounds.size.height;
  23. //  drho=pinc*(20*xdif);    // Increment for angle
  24. //  drad=pinc*(5*ydif);        // Number of increments
  25.  
  26. // A simple way of setting drho and drad
  27.   drho=0.11*(mx-midx);
  28.   drad=0.11*(my-midy);
  29.  
  30. //Prevent context-change during drawing? I dunno...
  31. //[self lockFocus];
  32.  
  33. // Set color to erase 
  34.   PSsetrgbcolor(0,0,0);    
  35.  
  36. // Wait till postscript server is done drawing
  37. //  DPSWaitContext(DPSGetCurrentContext());
  38. //  NXPing();
  39.  
  40. //  PSsetlinewidth( LINEWIDTH );
  41.  
  42. // Erase old user path to Postscript server
  43.   DPSDoUserPath(pts, p, dps_float, ops, NUMLINES, bbox, dps_ustroke);
  44.  
  45. // Set initial values 
  46.   if (c>MAXINT) c=0;
  47.   c++;
  48.   ops[0] = dps_moveto;
  49.   rho[0] = rho[NUMLINES-1];
  50.   rad = sin(c*drad);
  51.   pts[0] = (cos(rho[0])*rad*xscale) + midx;
  52.   pts[1] = (sin(rho[0])*rad*yscale) + midy;
  53.   p=2;
  54.  
  55.   for ( n = 1; n < NUMLINES; ++n)
  56.   {  c++;
  57.      rho[n] = rho[n-1]+drho;     if(rho[n]>(TWOP)) rho[n]-=(TWOP);
  58.      rad = sin(c*drad);
  59.  
  60.      // Store the op in da user path
  61.      ops[n] = dps_lineto;
  62.  
  63.      // Store x/y of the current point in the user path 
  64.      pts[p++] = (cos(rho[n])*rad*xscale) + midx;
  65.      pts[p++] = (sin(rho[n])*rad*yscale) + midy;
  66.   }
  67.   PSsetrgbcolor(0,1,1);
  68.  
  69. // Sync with server, needed when Numlines is high. Slows things down
  70. //  NXPing();
  71.  
  72. // DRAW the pattern: Send user path to Postscript server
  73.   DPSDoUserPath(pts, p, dps_float, ops, NUMLINES, bbox, dps_ustroke);
  74.  
  75. // [self unlockFocus];
  76.   return self;
  77. }
  78.  
  79.  
  80. - initFrame:(NXRect *)frameRect
  81. {
  82. // Wait till postscript server is done drawing
  83. //  DPSWaitContext(DPSGetCurrentContext());
  84. //  DPSFlushContext(DPSGetCurrentContext());
  85. //  NXPing();
  86.  
  87.   [super initFrame:frameRect];
  88.   [self newSize];
  89.   winNum=[[self window] windowNum];
  90.   return self;
  91. }
  92.  
  93.  
  94. - sizeTo:(NXCoord)width :(NXCoord)height
  95. {
  96. // Wait till postscript server is done drawing
  97. //  DPSWaitContext(DPSGetCurrentContext());
  98. //  DPSFlushContext(DPSGetCurrentContext());
  99. //  NXPing();
  100.  
  101.   [super sizeTo:width :height];
  102.   [self newSize];
  103.   return self;
  104. }
  105.  
  106. - newSize
  107. {
  108.   int jkl;
  109.  
  110. // Wait till postscript server is done drawing
  111. //  DPSWaitContext(DPSGetCurrentContext());
  112. //  DPSFlushContext(DPSGetCurrentContext());
  113. //  NXPing();
  114.   
  115. // Set up an array called boundingbox (req'd for user path)
  116.   bbox[0]=bounds.origin.x;
  117.   bbox[1]=bounds.origin.y;
  118.   bbox[2]=bounds.origin.x+bounds.size.width-1;
  119.   bbox[3]=bounds.origin.y+bounds.size.height-1;
  120.  
  121. // Reset c counter
  122.   c=0;
  123.  
  124. // Store middle of view.  
  125.   midx=bounds.origin.x+bounds.size.width/2;
  126.   midy=bounds.origin.y+bounds.size.height/2;
  127.  
  128. // Set value that scales drawing size.  Maintain 1 to 1 aspext ratio
  129.   xscale=0.29*bounds.size.width;
  130.   yscale=0.37*bounds.size.height;
  131.  
  132. // When a new view is initialized, ONESTEP will not have calculated
  133. // the lines to erase yet, so we have to do this for it...
  134.   for(jkl=0;jkl<TWONUMLN;jkl++){
  135.     pts[jkl]=midx;
  136.     pts[jkl]=midy;
  137.   }
  138.   for(jkl=0;jkl<NUMLINES;jkl++){
  139.     ops[0] = dps_moveto;}
  140.  
  141.   return self;
  142. }
  143.  
  144. @end
  145.